"use strict";

/**
 * @ngdoc directive
 * @name jgappApp.directive:flowRemind
 * @description
 * # flowRemind
 */
angular
  .module("jgappApp")
  .directive("fallBack", function (DataService, $rootScope, openApi, Util) {
    return {
      scope: {
        taskid: "=",
      },
      templateUrl: "views/directive/fallback.html",
      restrict: "AE",
      link: function postLink(scope) {
        // 撤回流程
        scope.confirm = function () {
          if (!scope.targetNodeId) {
            Util.Toast("请选择回退节点");
            return;
          }
          var param = {
            targetNodeId: scope.targetNodeId,
            taskId: scope.taskid,
          };

          DataService.getData(openApi.fallBackTask, param).then(function (
            data
          ) {
            Util.Toast(data, {
              callback: function () {
                NativeUtil.use("close");
              },
              time: 1000,
            });
            NativeUtil.use("updateProcess");
          });
        };

        scope.cancel = function () {
          $rootScope.$emit("closemasker");
        };

        $rootScope.$on("maskerClosed", function () {
          $rootScope.fallbacktemplate.remove();
        });

        scope.getFLowlist = function () {
          DataService.getData(openApi.fallbacklist, {
            taskId: scope.taskid,
          }).then(function (data) {
            scope.list = data;
          });
        };
        scope.$watch("taskid", function (newvalue) {
          if (newvalue) {
            scope.getFLowlist();
          }
        });
      },
    };
  });
